
<link rel="stylesheet" href="${resource(dir:'css',file:'cupertino/jquery-ui-1.8.custom.css')}" />
<g:javascript src="jquery/jquery-ui-1.8.custom.min.js"/>

<script language="javascript"> 

    $(document).ready(function() {      
//        $(".everyCourse").mouseover(function(){
//            $('.everyCourse').removeClass('mouseoverBag');
//            if($(this).attr('course') != ""){
//                $('.'+$(this).attr('course')).addClass('mouseoverBag');
//            }
//        });
 
        $("#course").change(function(){
            $("#teacher").html($("#"+$(this).val()).val())
        })

        $("#deleteSelectTeacherCourse").click(function(){
        
        
        })

        $(".everyCourse").click(function(){
            if($(this).attr('course') != ""){
                course = $(this).attr('course')
                teacher = $(this).attr('teacherId')
                $('#course option').each(function(){   
                        if( $(this).val() == course){   
                            $(this).attr('selected','selected'); 
                            $("#teacher").html($("#"+$(this).val()).val())
                            $("#teacher option").each(function(){ 
                                if( $(this).val() == teacher){ 
                                    $(this).attr('selected','selected'); 
                                }
                            });
                        }
                });
            }
            $('#dialog-form').dialog( "option" , "courseID" , [$(this).attr("id")] ) 
            $('#dialog-form').dialog( "option" , "teacherId" , [$(this).attr("teacherId")] ) 
            $('#dialog-form').dialog( "option" , "courseName" , [$(this).attr("course")] ) 
            $('#dialog-form').dialog('open');
        })    
        $("#dialog-form").dialog({
			autoOpen: false,
			height: 300,
			width: 300,
			modal: true,
			buttons: {
				'确定': function() {
                    if($("#course").val() == "" || $("#course").val() == null || $("#teacher").val() == "" || $("#teacher").val() == null){
                        alert("请选择课程和教师")
                    }   
                    var courseID = $('#dialog-form').dialog( "option" , "courseID")
                    var teacherId = $('#dialog-form').dialog( "option" , "teacherId")
                    var courseName = $('#dialog-form').dialog( "option" , "courseName")


                    if(teacherId != $("#teacher").val() || courseName != $("#course").val()){
                        // 验证此老师在本时间是否已经有课了
                        $.post("/cloud/planAjax/validResetTeacherCourseTime", {time:new Date().getTime(),teacherID:$('#teacher').val(),planID:$("#"+courseID).attr("planID")}, function(data) {
                             if( data.success == false ){
                                $('#validName').html(data.message);
                                
                            }else{
                                $('#validName').html(data.message);
                                $("#"+courseID).html($("#course").val()+"<br>("+$("#teacher").find("option:selected").text()+")")

                                if($('#courseTeacher'+courseID).length > 0){
                                    $('#courseTeacher'+courseID).val($("#"+courseID).attr("planID")+","+$("#teacher").val()+","+$("#course").val())
                                }else{
                                    $("#postResetCourseAndTeacher").append('<input type="hidden" id="courseTeacher'+courseID+'" name="courseAndTeacher" value="'+$("#"+courseID).attr("planID")+","+$("#teacher").val()+","+$("#course").val()+'"/>')
                                }

                                $("#dialog-form").dialog('close');
                                $('#validName').html("");
                                $("#course").val("")
                                $("#teacher").html("");
                                $("#teacher").val("");
                            }
                        }, 'json');
                    }else{
                        $("#dialog-form").dialog('close');
                    }
				},
				'清除课程':function() {
                    var courseID = $('#dialog-form').dialog( "option" , "courseID")
                    var teacherId = $('#dialog-form').dialog( "option" , "teacherId")
                    var courseName = $('#dialog-form').dialog( "option" , "courseName")

                    if(teacherId != "" && courseName !=""){
                        if($('#courseTeacher'+courseID).length > 0){
                            $('#courseTeacher'+courseID).val($("#"+courseID).attr("planID")+",'',''")
                        }else{
                            $("#postResetCourseAndTeacher").append('<input type="hidden" id="courseTeacher'+courseID+'" name="courseAndTeacher" value="'+$("#"+courseID).attr("planID")+',"","""/>')
                        }
                        $("#"+courseID).attr("teacherId","")
                        $("#"+courseID).attr("course","")
                        $("#"+courseID).html("")
                    }

                    $(this).dialog('close');
				},
				'取消':function() {
					$(this).dialog('close');
				}
			},
			close: function() {
				//allFields.val('').removeClass('ui-state-error');
			}
		});
    }); 
</script> 